package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.CustomerConsultation;
import com.by.bean.CustomerInquiry;
import com.by.bean.CustomerInquiryDetail;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.querypage.CustomerInquiryQuery;
import com.by.service.CustomerInquiryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "客户询价")
@RestController
@RequestMapping("/api")
@CrossOrigin
public class CustomerInquiryController extends BaseController {

    @Autowired
    CustomerInquiryService customerInquiryService;



    @ApiOperation("保存询价单")
    @PostMapping("/inquiry")
    public ResultBean save(@RequestBody CustomerInquiry customerInquiry){
        int rs = customerInquiryService.save(customerInquiry);
        return saveResult(rs);
    }


    @ApiOperation("询价单列表")
    @PostMapping("/inquiry/query")
    public ResultBean<PageBean> query(@RequestBody CustomerInquiryQuery query){
        PageBean pageBean = customerInquiryService.queryByMap(BeanUtil.beanToMap(query));
        return success("询价单列表",pageBean);
    }


    @ApiOperation("保存咨询单")
    @PostMapping("/consultation")
    public ResultBean saveConsultation(@RequestBody CustomerInquiry customerInquiry){
        int rs = customerInquiryService.saveConsultation(customerInquiry);
        return saveResult(rs);
    }

    @ApiOperation("询价明细")
    @GetMapping("/inquiry/detail")
    public ResultBean queryById(int id){
        List<CustomerInquiryDetail> rs = customerInquiryService.queryById(id);
        return success("询价明细",rs);
    }

}
